package com.hnevc.androidui11;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String json1 ="{\"name\":\"zhangsan\",\"age:27,\"married\":true}";
        Gson gson=new Gson();
        Person person= gson.fromJson(json1,Person.class);
        String json2 ="{\"2\",\"3\",\"4\"}";
        Type listType2 =new TypeToken<List<String>>(){}.getType();
        List<String> lis = gson.fromJson(json2,listType2);



        String json4="";
        InputStream inputStream=getResources().openRawResource(R.raw.weather2);
        try {
            byte[]buffer=new byte[inputStream.available()];
            inputStream.read(buffer);
           json4= new String(buffer);
            Type listType = new TypeToken<List<Weather>>() {
            }.getType();
           List<Weather> weatherList =gson.fromJson(json4,listType);
            Toast.makeText(this, weatherList.get(1).getweather(), Toast.LENGTH_SHORT).show();
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
